package com.example.administrator.leargit.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.leargit.activity.BaseActivity;
import com.example.administrator.leargit.activity.CommonAvtivity;

/**
 * Created by Administrator on 2016/12/22 0022.
 */
public abstract class Basefragment extends Fragment {

    private String TAG;
    private String  title;
    protected Context mContext;
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTAG() {
        if (TAG==null&&TAG.equals("")){
            TAG=getClass().getSimpleName();
        }
        return TAG;
    }

    public void setTAG(String TAG) {
        this.TAG = TAG;
    }

    protected BaseActivity mActivity;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext=mActivity= (BaseActivity) getActivity();
        initData();
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        View view = getView();

        if (view != null) {
            view.setClickable(true);
            /**
             * 初始化 view视图
             * */
            onInitView(view);
        }

        getData();

    }
   protected  abstract  View onCreateFragmentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState);
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view;
        view = inflater.inflate(null, container, false);



        return view;
    }

    public boolean onBackPressed() {

        return false;
    }
    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
    }

    protected String getMobclickName() {
        return getClass().getSimpleName();
    }
    /**
 * 初始化视图
 * */
    protected abstract void onInitView(View view);

    /**
     * 初始化数据
    * */
    private void initData() {
        Bundle  bundle=getArguments();
        if (bundle == null) {
            bundle = new Bundle();
        }


        onInitData(bundle);
    }

    private void onInitData(Bundle bundle) {


    }

    @Override
    public void setArguments(Bundle args) {
        super.setArguments(args);
    }

    public void getData() {
       onGetData();
    }

    private void onGetData() {

    }

    public void finish(){

    }

    public abstract void onInitActionBar(CommonAvtivity commonAvtivity);

}
